package com.lanchuan.soft.utils;

import lombok.extern.log4j.Log4j2;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import java.text.SimpleDateFormat;
import java.util.Date;

@Log4j2
public class Test {

    public static String createKeyId() {
        int min = 10000;
        int max = 100000;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
        String datetime = sdf.format(new Date());
        StringBuilder sb = new StringBuilder();
        sb.append(datetime);
        int current = (int) Math.floor(Math.random() * (max - min) + min);
        sb.append(current);
        return sb.toString();
    }

    public static void main(String[] args) {
        createUser();
//        log.info(createKeyId());
    }

    // 添加用户
    public static void createUser() {

//        String str = "[{\"name\":\"张卫平\",\"username\":\"13703317653\",\"org\":\"2019050909110773763245-2019050909174330142411\"}]";
//        String str = "[{\"name\":\"陈建芳\",\"username\":\"13931853552\"},{\"name\":\"赵红伟\",\"username\":\"15076311760\"},{\"name\":\"高修雷\",\"username\":\"17367716292\"},{\"name\":\"刘志敏\",\"username\":\"18031188561\"},{\"name\":\"段炳赛\",\"username\":\"15200009181\"},{\"name\":\"陈强\",\"username\":\"13931889840\"},{\"name\":\"刘刚\",\"username\":\"13703318298\"},{\"name\":\"冯哲\",\"username\":\"13315150247\"},{\"name\":\"何慧刚\",\"username\":\"18731125898\"},{\"name\":\"王帅康\",\"username\":\"15930197992\"},{\"name\":\"刘金生\",\"username\":\"18731126186\"},{\"name\":\"杨苗\",\"username\":\"18532109589\"},{\"name\":\"闫增军\",\"username\":\"13582361159\"},{\"name\":\"白帆\",\"username\":\"15532169600\"}]";
        String str = "[{\"nickname\":\"刘建亮\",\"username\":\"18532107258\",\"org\":\"2019050909110773763245-2019050909202815766480\"},{\"nickname\":\"朱凤泉\",\"username\":\"13633113789\",\"org\":\"2019050909110773763245-2019050909202815766480\"},{\"nickname\":\"许占国\",\"username\":\"18532108951\",\"org\":\"2019050909110773763245-2019050909202815766480\"},{\"nickname\":\"祁磊\",\"username\":\"13673213000\",\"org\":\"2019050909110773763245-2019050909202815766480\"},{\"nickname\":\"段启霖\",\"username\":\"13831193946\",\"org\":\"2019050909110773763245-2019050909202815766480\"}]";

        JSONArray array = JSONArray.fromObject(str);

        JSONObject jsonObject;
        StringBuilder sql = new StringBuilder();
        for (Object o : array) {
            jsonObject = JSONObject.fromObject(o);


            sql.append("INSERT INTO sjz_user VALUES('").append(createKeyId()).append("', '").append("2019050909110773763245-2019050909202815766480").append("', '").append(jsonObject.get("username")).append("', 'e10adc3949ba59abbe56e057f20f883e', '").append(jsonObject.get("nickname")).append("', 1, 1, NOW());\n\r\t");
        }
        log.info(sql.toString());
    }

    public static void createPt() {
        String org = "2019050909191796918662";
        String username = "test";
        String nickname = "测试";

        String sql1 = "INSERT INTO sjz_user VALUES ('" + createKeyId() + "', '2019050909110773763245-" + org + "', '" + username + "jdpt', 'e10adc3949ba59abbe56e057f20f883e', '" + nickname + "街道平台', 2, 1, NOW());\n\r\t";
        String sql2 = "INSERT INTO sjz_user VALUES ('" + createKeyId() + "', '2019050909110773763245-" + org + "', '" + username + "jdzr', 'e10adc3949ba59abbe56e057f20f883e', '" + nickname + "街道决策中心', 3, 1, NOW());\n\r\t";

        log.info(sql1 + sql2);
    }
}
